/*
Licensed under the terms of LGPL license
Author : redprogrammer
Autor Mail: redprogrammer@gmail.com
Source Website: www.redplugin.com

GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

read LGPL license.txt for whole license conditions
*/
$(document).ready(function(){
	jQuery.fn.redswap = function(options){
		var selectedItems=this;
		redsettings = jQuery.extend({
			 speed:"Medium",
			 opacity:0.7
		  }, options);
		$(selectedItems).mouseover(function(){
			$(selectedItems).disableSelection();
			$(selectedItems).droppable({
				drop: function(event, ui){
					dropindex=$(selectedItems).index(this);
					var dragposition=$(selectedItems[dragindex]).position();
					var dropposition=$(selectedItems[dropindex]).position();
					
					withDifference=parseInt(dragposition.left)-parseInt(dropposition.left);
					heightDifference=parseInt(dragposition.top)-parseInt(dropposition.top);
					
					$(selectedItems[dropindex]).animate({
						left:'+='+withDifference,
						top:'+='+heightDifference
					},redsettings.speed,function(){
						
					});					
					$(selectedItems[dragindex]).animate({
						left:'+='+(withDifference*(-1)),
						top:'+='+(heightDifference*(-1))
					},redsettings.speed,function(){
						//Complete
					});					
				}		
			});			
			$(this).draggable({ 
			opacity:redsettings.opacity, 
			helper: 'clone',
			containment: 'parent', 
			scroll: false,
			drag:function(event, ui){
					dragindex=$(selectedItems).index(this);
				}				
			});			
		});
	};	
});